﻿using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using OpenAdmin.Application.Services;
using OpenAdmin.Application.Services.Dtos;

namespace OpenAdmin.HttpApi.Controllers;

/// <summary>
/// 租户相关Api
/// </summary>
[ApiExplorerSettings(GroupName = "Application")]
public class TenantController : ApiControllerBase
{
    private readonly ITenantService _tenantServices;
    /// <summary>
    /// 构造函数
    /// </summary>
    public TenantController(ITenantService tenantServices)
    {
        _tenantServices = tenantServices;
    }

    /// <summary>
    /// 获取租户列表(分页)
    /// </summary>
    /// <returns></returns>
    [HttpGet, ProducesResponseType(typeof(PagedList<TenantsByPageResponseDto>), 200)]
    public async Task<IActionResult> GetTenantsByPage([FromQuery] TenantsByPageRequestDto requestDto)
    {
        return Ok(await _tenantServices.GetTenantsByPage(requestDto));
    }

    /// <summary>
    /// 添加租户
    /// </summary>
    /// <param name="requestDto"></param>
    /// <returns></returns>
    [HttpPost]
    public async Task<IActionResult> AddTenant(AddTenantRequestDto requestDto)
    {
        await _tenantServices.AddTenant(requestDto);

        return Ok();
    }

    /// <summary>
    /// 更新租户信息
    /// </summary>
    /// <param name="requestDto"></param>
    [HttpPost]
    public async Task<IActionResult> EditTenant(EditTenantRequestDto requestDto)
    {
        await _tenantServices.EditTenant(requestDto);

        return Ok();
    }

    /// <summary>
    /// 删除租户
    /// </summary>
    /// <param name="tenantId"></param>
    [HttpPost]
    public async Task<IActionResult> DeleteTenant(string tenantId)
    {
        await _tenantServices.DeleteTenant(tenantId);

        return Ok();
    }
}
